package com.ysq.www.api.user.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ysq.www.api.user.entity.Comment;
import com.ysq.www.api.user.mapper.CommentMapper;
import com.ysq.www.api.user.service.ICommentService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ysq.www.common.result.ResultMsg;
import com.ysq.www.common.utils.Comm;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 评论表 服务实现类
 * </p>
 *
 * @author dql
 * @since 2020-08-18
 */
@Service
public class CommentServiceImpl extends ServiceImpl<CommentMapper, Comment> implements ICommentService {

    @Autowired
    private CommentMapper commentMapper;

    /**
     * 分页查询评论
     * @param type 评论类型：1资讯
     * @param cId 内容id
     * @param pageNumber 页码
     * @param pageSize 页大小
     * @return IPage
     */
    @Override
    public IPage<Comment> selectListById(Integer type, Integer cId, Integer pageNumber, Integer pageSize) {
        Page<Comment> page = new Page<>(pageNumber,pageSize);
        IPage<Comment> cPage = commentMapper.selectListByPage(page,type,cId);
        return cPage;
    }

    /**
     * 新增评论
     * @param comment 评论对象
     * @return ResultMsg
     */
    @Override
    public ResultMsg addComment(Comment comment) {
        comment.setCreateTime(Comm.getNow());
        comment.setStatus(0);
        comment.setUpdateTime(Comm.getNow());
        this.save(comment);
        return ResultMsg.INSERT_SUCCESS;
    }
}
